package com.atguigu.seckill.controller;


import com.atguigu.seckill.service.IUserService;
import com.atguigu.seckill.vo.CodeResponse;
import com.atguigu.seckill.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@Slf4j
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/doLogin")
    @ResponseBody
    public CodeResponse  doLogin(@Valid LoginVo loginVo, HttpServletRequest request , HttpServletResponse response){
        //将号码和密码以日志打印到控制台
        log.info("{}",loginVo);
        //调用service
        return userService.loginService(loginVo,request,response);
    }
}
